{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Improved gang wars"

if
    is_game_first_start
then
    0F00: load_special_model_dff "modelsqa\gngblproof1" txd "modelsqa\gngblproof" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Improved Gangs War.ini" section "Models" key "gngblproof1"

    0F00: load_special_model_dff "modelsqa\gngblproof2" txd "modelsqa\gngblproof" store_to 0@
    0AF1: write_int 0@ to_ini_file "cleo\Improved Gangs War.ini" section "Models" key "gngblproof2"
end

const
    Speed_anim = 31@
    Bulletprf_1 = 30@
    Bulletprf_2 = 29@
    exception_1 = 28@
    exception_2 = 27@
    exception_3 = 26@
    exception_4 = 25@
    exception_5 = 24@
    exception_6 = 23@
    exception_7 = 22@
    Scr_bulletproof = 21@
    Scr_faster = 20@
    Improved_Gangs_Spawn = 19@
    Scr_sound = 18@
    Scr_visual = 17@
    vis_x = 16@
    vis_y = 15@
    size_x = 14@
    size_y = 13@
    text_x = 12@
    text_y = 11@
    text_mode = 10@
end

0AF2: Speed_anim = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Faster and Climbing" key "Run Animation Speed"
0AF0: Improved_Gangs_Spawn = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Faster and Climbing" key "Improved Gangs Spawn"

0AF0: Scr_bulletproof = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Settings" key "Bulletproof"
0AF0: Scr_faster = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Settings" key "Faster and Climbing"
0AF0: Scr_sound = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Settings" key "Gangs Ambient Sound"
0AF0: Scr_visual = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Settings" key "Visual"

0AF0: exception_1 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 1"
0AF0: exception_2 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 2"
0AF0: exception_3 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 3"
0AF0: exception_4 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 4"
0AF0: exception_5 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 5"
0AF0: exception_6 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 6"
0AF0: exception_7 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Bulletproof" key "Exception Ped ID 7"

0AF0: Bulletprf_1 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Models" key "gngblproof1"
0AF0: Bulletprf_2 = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Models" key "gngblproof2"

0AF2: vis_x = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "X"
0AF2: vis_y = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "Y"
0AF2: size_x = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "Size X"
0AF2: size_y = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "Size Y"
0AF2: text_x = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "Text Position X"
0AF2: text_y = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "Text Position Y"
0AF0: text_mode = read_int_from_ini_file "cleo\Improved Gangs War.ini" section "Visual" key "Text"

While true
wait 0
    if
        player.Defined(0)
    then
        if
            087A:   gang_war_in_progress
        then
        
            0A8D: 2@  = read_memory 0x96AB64 size 1 virtual_protect 0 //  mov     eax, ds:_ZN9CGangWars5StateE ; CGangWars::State
        
            0AAA: 1@ = get_script_struct_named "GNGVIS"
            if and
                Scr_visual == 1
                1@ == 0
                2@ >= 1
            then
                0A92: stream_custom_script "Gang War Visual.qa" vis_x vis_y size_x size_y text_x text_y text_mode
                wait 1000
                continue
            end
            
            0AAA: 1@ = get_script_struct_named "GNGMUS"
            if and
                Scr_sound == 1
                1@ == 0
                2@ >= 1
                80DF:   not actor $PLAYER_ACTOR driving
            then
                0A92: stream_custom_script "Gangs Amb Sound.qa"
                wait 1000
                continue
            end
        
            0AAA: 1@ = get_script_struct_named "GNGBLT"
            if and
                Scr_bulletproof == 1
                1@ == 0
                2@ == 1
            then
                0A92: stream_custom_script "Bulletproof.qa" exception_1 exception_2 exception_3 exception_4 exception_5 exception_6 exception_7 Bulletprf_1 Bulletprf_2
                wait 1000
                continue
            end

            0AAA: 1@ = get_script_struct_named "GNGFST"
            if and
                Scr_faster == 1
                1@ == 0
            then
                0A92: stream_custom_script "Faster.qa" Speed_anim Improved_Gangs_Spawn
                wait 1000
                continue
            end
            
            
        end
    end
end